//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssProductStockHisDao;
import com.aidong.model.wills.PssProductStockHisExt;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.pss.PopProductController;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"productStockHisList"})
public class ProductStockHisListController extends PopProductController {
    @Resource
    PssProductStockHisDao pssProductStockHisDao;

    public ProductStockHisListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("pss/productstockhis/list")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "productCode",required = false) String productCode, @RequestParam(value = "savemonth",required = false) String savemonth, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "a.ShopCode", shopCode);
        if(!this.chkNull(productCode)) {
            cd.eq("a.ProductCode", productCode);
        }

        if(!this.chkNull(savemonth)) {
            cd.eq("a.SaveMonth", savemonth);
        }

        this.pssProductStockHisDao.getProductStockHisLst(pg, cd);
        ModelAndView mv = new ModelAndView("pss/productstockhis/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("productUnit", this.getTypeList("productUnit"));
        mv.addObject("ProductcodeList", this.getTypeList("ProductcodeList"));
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "productCode",required = false) String productCode, @RequestParam(value = "savemonth",required = false) String savemonth, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, 20000);
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "a.ShopCode", shopCode);
            if(!this.chkNull(productCode)) {
                cd.eq("a.ProductCode", productCode);
            }

            if(!this.chkNull(savemonth)) {
                cd.eq("a.SaveMonth", savemonth);
            }

            this.pssProductStockHisDao.getProductStockHisLst(e, cd);
            ExportXls xls = new ExportXls(response, "商品库存历史数据", "商品库存历史数据");
            xls.addHead(new String[]{"门店编号", "门店名称", "商品编码", "商品名称", "单位", "数量", "保存月份"});
            xls.setWidth(new int[]{10, 15, 10, 30, 10, 10, 10});
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                PssProductStockHisExt puot = (PssProductStockHisExt)i$.next();
                xls.addRow(new Object[]{puot.getShopCode(), this.cache.getValue("shopName", puot.getShopCode()), puot.getProductCode(), this.cache.getValue("ProductcodeList", puot.getProductCode()), this.cache.getValue("productUnit", puot.getUnit()), puot.getQuantity(), puot.getSaveMonth()});
            }

            xls.close();
            this.addUserLog("导出商品库存历史数据", e.getResultList().size() + "条记录");
        } catch (Exception var10) {
            this.log.error("import", var10);
        }

        return null;
    }
}
